const fs = require("fs")

const diff = (originFile, newFile) => {
    return new Promise((reslove, reject) => {
        fs.exists('patch/',
            exist => {
                if (!exist) {
                    fs.mkdir('patch/')
                }
            }
        )
        var timetamp4 = Number(new Date())
        exec(
            `bsdiff.exe ${originFile} ${newFile} patch/${timetamp4}.patch`,
            function (code, stdout, stderr) {
                console.log('Exit code:', code)
                console.log('Program output:', stdout)
                console.log('Program stderr:', stderr)
                if (code == 0) {
                    reslove(`patch/${timetamp4}.patch`)
                } else {
                    reject(new Error(stderr))
                }
            }
        )
    })
}

module.exports = {
    diff
}